#include "MapList.h"


map<string, CustomizedMap> MapList::getMap(){
	return this->mapList;
}

std::string MapList::getType(){
	return this->type;
}


void MapList::setType(std::string value){
	this->type = value;
}


CustomizedMap* MapList::getElement(std::string key) throw (ElementNotFoundException){
	map<string, CustomizedMap>::iterator ii;

	for(ii= this->mapList.begin(); ii!=this->mapList.end(); ++ii){	   
	   if ((*ii).first == key){
	   CustomizedMap map = ((CustomizedMap)(*ii).second);
	   return new CustomizedMap(map.customMap);
	   }
	}
	
	throw ElementNotFoundException("El elemento que busca no se encuentra en el mapa");

}

int MapList::getElementQuantity(){
	return mapList.size();
}

bool MapList::isValid(){
	bool valid = true;
	if(isElementValid()){
		map<string, CustomizedMap>::iterator ii;
		for(ii= this->mapList.begin(); ii!=this->mapList.end(); ++ii){
			CustomizedMap map = ((CustomizedMap)(*ii).second);
			valid=valid&&map.isValid(ObjectTypeUtils::getObjectTypeByString(this->type),(*ii).first);
		}
		return valid;
	}
	else return false;
}

bool MapList::isValidGeneralTag(){
	int attributeCounter=0;
	if(mapList.find("resolucion")!=mapList.end())attributeCounter++;
	if(mapList.find("colorFondoGraf")!=mapList.end())attributeCounter++;
	if(mapList.find("textura")!=mapList.end())attributeCounter++;
	if(mapList.find("colorLinea")!=mapList.end())attributeCounter++;
	if(mapList.find("colorFondo")!=mapList.end())attributeCounter++;
	return (mapList.size()==attributeCounter);
}


bool MapList::isElementValid(){
	ObjectType type = ObjectTypeUtils::getObjectTypeByString(this->type);
	switch(type){
		case square:return (MapList::getElementQuantity()==2);
		case circle:return (MapList::getElementQuantity()==2);
		case segment:return (MapList::getElementQuantity()==3);
		case rectangle:return (MapList::getElementQuantity()==2);
		case texture:return (MapList::getElementQuantity()==1);
		case general:return isValidGeneralTag();
		default: return false;
	}
}